package com.itheima1.controller;

import com.itheima1.domain.Student;
import com.itheima1.service.StudentService;
import com.itheima1.service.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    private StudentService service = new StudentServiceImpl();
@Test
    public  void findAll() {
        ArrayList<Student> list = service.findAll();
        for (Student stu : list) {
            System.out.println(stu);
        }
    }



   @Test //根据id查找的测试方法
    public void findById() {
        Student byId = service.findById(3);
        System.out.println(byId);
    }


    //添加学生
    @Test
    public  void insert() {
        Student stu = new Student(5, "赵四", 15, new Date());

        int insert = service.insert(stu);
        if (insert != 0) {
            System.out.println("添加成功");

        } else {
            System.out.println("添加失败");
        }
    }


    //修改学生
    @Test
    public  void update() {
        Student stu = service.findById(5);
        stu.setName("小飞机");
        int update = service.update(stu);
        if (update != 0) {
            System.out.println("修改成功");
        } else {

            System.out.println("修改失败");
        }
    }

    //删除学生
    @Test
    public  void delete() {
        int delete = service.delete(5);

        if (delete != 0) {
            System.out.println("删除成功");
        } else {
            System.out.println("删除失败");
        }
    }


}
